package com.junior.fixclub;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.junior.fixclub.activity.AppsActivity;
import com.junior.fixclub.activity.DevicesActivity;
import com.junior.fixclub.util.SDcardUtil;

import vip.ruoyun.permission.pro.DefaultAction;
import vip.ruoyun.permission.pro.MissPermission;
import vip.ruoyun.permission.pro.PermissionRequest;
import vip.ruoyun.permission.pro.ui.AgainRequestDialog;
import vip.ruoyun.permission.pro.ui.AlwaysDeniedDialog;
import vip.ruoyun.permission.pro.ui.RequestPromptDialog;

public class MainActivity extends AppCompatActivity {
    public static final int UPDATE = 0x1;
    public static Button checkPermission = null;
    public static Button choiceDevices = null;
    public static Button choiceApps = null;

    public Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            if (msg.what == 0x1) {
                if (msg.arg1 == 4) {
                    MainActivity.checkPermission.setClickable(false);
                    MainActivity.checkPermission.setBackgroundResource(R.color.colorOkClick);
                    MainActivity.checkPermission.setText("成功授权");
                    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                    builder.setTitle((CharSequence) "提示");
                    builder.setMessage((CharSequence) "获取权限成功，谢谢配合！");
                    builder.setPositiveButton((CharSequence) "好的", null);
                    builder.show();
                } else if (msg.arg1 == 5) {
                    MainActivity.checkPermission.setBackgroundResource(R.color.colorErrClick);
                    MainActivity.checkPermission.setText("重新授权");
                    AlertDialog.Builder builder2 = new AlertDialog.Builder(MainActivity.this);
                    builder2.setTitle((CharSequence) "提示");
                    builder2.setMessage((CharSequence) "获取有些权限失败，请重试！");
                    builder2.setPositiveButton((CharSequence) "好的", null);
                    builder2.show();
                }
            }
        }
    };

    static {
        System.loadLibrary("nativehook");
    }

    /* access modifiers changed from: protected */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView((int) R.layout.activity_main);
        checkPermission = (Button) findViewById(R.id.auth_check);
        checkPermission.setOnClickListener(new View.OnClickListener() {
            public void onClick(View i) {
                checkPermission();
            }
        });
        choiceDevices = (Button) findViewById(R.id.device_choice);
        choiceDevices.setOnClickListener(new View.OnClickListener() {
            public void onClick(View i) {
                Intent intent = new Intent(MainActivity.this,DevicesActivity.class);
                startActivity(intent);
            }
        });
        choiceApps = (Button) findViewById(R.id.app_choice);
        choiceApps.setOnClickListener(new View.OnClickListener() {
            public void onClick(View i) {
                Intent intent = new Intent(MainActivity.this, AppsActivity.class);
                startActivity(intent);
            }
        });
        SDcardUtil.getInstance(this).copyAssetsToSD("fixclub","fixclub");
    }

    public void checkPermission() {
        MissPermission.with().
        permission("android.permission.ACCESS_FINE_LOCATION").
        permission("android.permission.READ_EXTERNAL_STORAGE").
        permission("android.permission.WRITE_EXTERNAL_STORAGE").
        permission("android.permission.READ_PHONE_STATE").
        prompt(true).
        msg("为了正常运行要以下权限").
        title("亲爱的用户").
        style(R.style.MissPermissionDefaultNormalStyle).
        action(new DefaultAction() {
            public void onActivityResult(int resultCode, Intent data) {
                //
            }

            public void onCreateRequestPromptDialog(RequestPromptDialog requestPromptDialog) {
                //
            }

            public void onCreateAlwaysDeniedDialog(AlwaysDeniedDialog getAlwaysDeniedDialog) {
                //
            }

            public void onCreateAgainRequestDialog(AgainRequestDialog getAgainRequestDialog) {
                //
            }
        }).check(new PermissionRequest.PermissionListener() {
            public void onSuccess(PermissionRequest request) {
                Message msg = new Message();
                msg.what = 0x1;
                msg.arg1 = 4;
                MainActivity.this.mHandler.sendMessage(msg);
            }

            public void onFailure(PermissionRequest request) {
                Message msg = new Message();
                msg.what = 0x1;
                msg.arg1 = 5;
                MainActivity.this.mHandler.sendMessage(msg);
            }
        });
    }
}
